﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pharmacy_Manage_System.Model;
using DealPrint;
using grproLib;
using System.Data.SqlClient;
using DataService;
using System.Reflection;

namespace 静配辅助程序打印测试
{
    public partial class Form1 : Form
    {
        public string connstr = "";
        public string prescription = "";
        public string windowno = "";
        public string PrintTitle = "";//打印标题
        public string printerName = "";//打印机名称
        public string flag = "2";  // 1：第一次打印   2：重新打印
        public string grffile = @"\NormalPres_DH_Test.grf";

        public DBConnection conn = new DBConnection();

        //private GridppReport Report = new GridppReport();
        public Form1()
        {
            connstr = "Data Source=.;User ID=sa;Password=sa-123;Initial Catalog=INTG_DH_LPS;Connect Timeout =5";
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<T_LabelHisIronData> lst = GetPrintLabel(new T_LabelHisIronData() { LabelNo = "008692,22801894,2019-10-19,17" }, "1", "1");

            ////单条数据
            //dynamic data = new List<KeyValuePair<string, object>>()
            //{
            //    new KeyValuePair<string, object>("LabelNo","12345678"),
            //    new KeyValuePair<string, object>("WardName","神经内科"),
            //    new KeyValuePair<string, object>("DrugName","药品111"),
            //};

            ////列表数据
            //List<dynamic> data = new List<dynamic>()
            //{
            //   new List<KeyValuePair<string, object>>()
            //   {
            //     new KeyValuePair<string, object>("LabelNo","12345678"),
            //     new KeyValuePair<string, object>("WardName","神经内科"),
            //     new KeyValuePair<string, object>("DrugName","药品111"),
            //   },
            //   new List<KeyValuePair<string, object>>()
            //   {
            //     new KeyValuePair<string, object>("LabelNo","12345678"),
            //     new KeyValuePair<string, object>("WardName","神经内科"),
            //     new KeyValuePair<string, object>("DrugName","药品222"),
            //   }
            //};
            //foreach (KeyValuePair<string, object> col in data[0])
            //{
            //    string aa = col.Key;//属性
            //    string bb = col.Value.ToString();//值
            //}

            var file = Utility.GetRootPath() + grffile;
            Gridpp6.ReportDealClass<T_LabelHisIronData> r = new Gridpp6.ReportDealClass<T_LabelHisIronData>(lst, file, "Microsoft Print to PDF");
            //Gridpp6.ReportDealClass<dynamic> r = new Gridpp6.ReportDealClass<dynamic>(data, file, "");
            r.ReportPrint(true);
        }


        public List<T_LabelHisIronData> GetPrintLabel(T_LabelHisIronData li, string flag, string printStatus)
        {
            //参数集合
            //SqlParameter[] paras ={new SqlParameter ("@MachineId",SqlDbType.VarChar ),
            //                       new SqlParameter ("@WardNO",SqlDbType.VarChar),
            //                       new SqlParameter ("@BedNO",SqlDbType.VarChar),
            //                       new SqlParameter ("@MedNO",SqlDbType.VarChar),
            //                       new SqlParameter ("@PresDate",SqlDbType.VarChar),    
            //                       new SqlParameter ("@SolentName",SqlDbType.VarChar),
            //                       new SqlParameter ("@MainMedName",SqlDbType.VarChar),
            //                       new SqlParameter ("@HistoryTime",SqlDbType.VarChar),
            //                       new SqlParameter ("@Flag",SqlDbType.VarChar),
            //                       new SqlParameter ("@OutMachine",SqlDbType.VarChar),
            //                       new SqlParameter ("@MedLabelNO",SqlDbType.VarChar)
            //                      };
            //paras[0].Value = li.MachineID == null ? "" : li.MachineID;
            //paras[1].Value = li.WardNo == null ? "" : li.WardNo;
            //paras[2].Value = li.BedNo == null ? "" : li.BedNo;
            //paras[3].Value = li.MedNo == null ? "" : li.MedNo;
            //DateTime presdate;
            //paras[4].Value = DateTime.TryParse(li.PresDate, out  presdate) ? presdate.ToString("yyyyMMdd") : li.PresDate;// Convert.ToDateTime(li.PresDate).ToString("yyyyMMdd");
            //paras[5].Value = li.SolventName == null ? "" : li.SolventName;
            //paras[6].Value = li.MainMedName == null ? "" : li.MainMedName;
            //paras[7].Value = li.HistoryTime == null ? "" : li.HistoryTime;
            //paras[8].Value = printStatus == null ? "" : printStatus;
            //paras[9].Value = flag == null ? "" : flag;
            //paras[10].Value = li.MedLabelNO == null ? "" : li.MedLabelNO;
            SqlParameter[] paras ={new SqlParameter ("@LabelNO",SqlDbType.VarChar )
                                  };
            paras[0].Value = li.LabelNo;
            GetDataProc<T_LabelHisIronData> gdp = new GetDataProc<T_LabelHisIronData>(connstr);
            List<T_LabelHisIronData> result = gdp.GetDataModel("P_LPS_GetLabelDetailsTest", paras);
            return result == null ? new List<T_LabelHisIronData>() : result;
        }

        public static string NumberToChinese(string numberStr)
        {
            string numStr = "0123456789";
            string chineseStr = "零一二三四五六七八九";
            char[] c = numberStr.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                int index = numStr.IndexOf(c[i]);
                if (index != -1)
                    c[i] = chineseStr.ToCharArray()[index];
            }
            numStr = null;
            chineseStr = null;
            return new string(c);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ParamTestModel param = new ParamTestModel();
            param.LabelNo = "125660,22720766,2019-10-19,17";
            ReportParamSQL<ParamTestModel> report = new ReportParamSQL<ParamTestModel>(param, Utility.GetRootPath() + @"\NormalPres_DH_Test_SP.grf", "");

            report.ReportPrint(true);
        }
    }

    public class T_LabelHisIronData : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public string RecipeID { get; set; }

        public string ZYNo { get; set; }

        public string LabelNo { get; set; }

        public string PresType { get; set; }

        public string DoctorName { get; set; }

        public string IsTemporary { get; set; }

        public string MedNo { get; set; }

        public string PresDate { get; set; }

        public string UseTime { get; set; }

        public string WardNo { get; set; }

        public string SWardName { get; set; }

        public string BedNo { get; set; }

        public string PatientID { get; set; }

        public string PatientName { get; set; }

        public string PatientSex { get; set; }

        public string PatientAge { get; set; }

        public string IsCompound { get; set; }

        public string presremarkOne { get; set; }

        public string presremarkTwo { get; set; }

        public string presremarkThree { get; set; }

        public string PutDrugPerson { get; set; }

        public string PutDrugPersonNo { get; set; }

        public string ExaminePerson { get; set; }

        public string ExaminePersonNo { get; set; }

        public string LabelPerson { get; set; }

        public string LabelPersonNo { get; set; }

        public string LExaminePerson { get; set; }

        public string LExaminePersonNo { get; set; }

        public string DataBatchNo { get; set; }

        public string IssueNo { get; set; }

        public int LabelIndex { get; set; }

        public string FreqCode { get; set; }

        public string DrugCode { get; set; }

        public string MedName { get; set; }

        public string MedUnit { get; set; }

        public string MedAmt { get; set; }

        public string DosageAmt { get; set; }

        public string DosageUnit { get; set; }
        public string Dosage { get; set; }
        public string MedDosage => DosageAmt + DosageUnit.Trim();

        /// <summary>
        /// 是否溶媒 1是
        /// </summary>
        public string Solvent { get; set; }
        public string GS1Code { get; set; }
        public string GS2Code { get; set; }
        public string DrugActAmt { get; set; }
        /// <summary>
        /// 注意信息
        /// </summary>
        public string AddInfo { get; set; }

        public string DrugRemark1 { get; set; }

        public string DrugRemark2 { get; set; }

        public string DrugRemark3 { get; set; }

        public string DrugRemark4 { get; set; }

        public string DrugUnitSup { get; set; }

        public string PrintCount { get; set; }
        public string TimeTag => UseTime;
        public string InterfaceRemark1 { get; set; }
        public string InterfaceRemark2 { get; set; }
        public string InterfaceRemark3 { get; set; }

        public string InterfaceRemark4 { get; set; }

        public string InterfaceRemark5 { get; set; }

        public string InterfaceRemark6 { get; set; }

        public string InterfaceRemark7 { get; set; }

        public string InterfaceRemark8 { get; set; }

        public string InterfaceRemark9 { get; set; }
        public string InterfaceRemark10 { get; set; }

        public string InterfaceRemark11 { get; set; }
        public string InterfaceRemark12 { get; set; }

        public string TagInfo => InterfaceRemark1;


    }

    public class ParamTestModel
    {
        public string LabelNo { get; set; }
    }

}
